<template>
    <div>
        <h1>房型添加</h1>
        <table class="table table-bordered" >
            <tr>
                <td>房型名称</td>
                <td>
                    <input type="text" v-model="fx.name">
                </td>
            </tr>
            <tr>
                <td>房型面积</td>
                <td>
                    <input type="text" v-model="fx.mianJi">
                </td>
            </tr>
            <tr>
                <td>价格</td>
                <td>
                    <input type="text" v-model="fx.money">
                </td>
            </tr>
            <tr>
                <td>是否有窗</td>
                <td>
                    <input type="radio" name="isNo" v-model="fx.isNo":value="0">无
                    <input type="radio" name="isNo" v-model="fx.isNo":value="1">有
                </td>
            </tr>
            <tr>
                <td>入住人数</td>
                <td>
                    <select v-model="fx.num">
                        <option value="">请选择</option>
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>状态</td>
                <td>
                    <input type="radio" name="states" v-model="fx.state":value="0">停用
                    <input type="radio" name="states" v-model="fx.state":value="1">启用
                </td>
            </tr>
            <tr>
                <td>图片</td>
                <td>
                    <input type="text" v-model="fx.photo">
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="修改" @click="save">
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { reactive, toRefs,onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import axios from 'axios';
let router = useRouter();
let route = useRoute();

let data:any=reactive({
    fx:{
      
  "name": "",
  "photo": "",
  "mianJi": '',
  "isNo": 0,
  "money":'',
  "num": '',
  "state": 0,
    },
});
let { fx } = toRefs(data);

const save = () => {
    let obj={
        id:route.query.id,
        name: fx.value.name,
        photo: fx.value.photo,
        mianJi: fx.value.mianJi,
        isNo: fx.value.isNo,
        money: fx.value.money,
        num: fx.value.num,
        state: fx.value.state,
    }
    axios({
        url: '/api/HouseX/Update',
        method: 'put',
        data: obj,
    }).then((res) => {
        if (res.data.data == 1) {
            alert('修改成功');
            router.push('/list');
        } else {
            alert('修改失败');
            return;
        }
    })
}

const FanTian=()=>{
    let obj={
        id:route.query.id,
    }
    axios({
        url: '/api/HouseX/FanTian',
        method: 'get',
        params: obj,
    }).then((res) => {
        fx.value=res.data.data;
    })
}

onMounted(()=>{
    FanTian();
})
</script>

<style scoped>

</style>